package net.onceface.web.resources;

import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import net.onceface.application.CategoryApplication;
import net.onceface.application.commons.InvokeResult;
import net.onceface.application.commons.Message;

/**
 * 分类资源类
 * **/
@Path("/category")
public class CategoryResource extends BaseResource{

	@Inject 
	CategoryApplication application;
	
	/**
	 * 获取可用分类列表
	 * **/
	@GET
	@Path("/getList")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public String getList(@Context HttpServletResponse response){
		if (response != null){
    		response.setHeader("Access-Control-Allow-Origin", "*");
    	}
		try{
			return toJson(InvokeResult.success(application.getList()));
		}catch(Exception e){
			return toJson(InvokeResult.failure(Message.GET_CATRGORY_FAILURE));
		}
	}
	
}
